//学校信息管理
async function schoolgetall(){
    response=await taskObject.fetchtemplate(path='/api/admin/school')
    dataform['schooldata']=response.data
    return response
}
!(async function(){
    response=await schoolgetall()
    let util=layui.util
    await rendertable(data=response['data'],domhtml='.school tbody',domdata=['id','collegename','timestamp'])
   
    for (const i in response['data']){
       
        $(`.school tbody tr:eq(${i})`).append(`<td><button class="layui-btn layui-bg-red " id=${response['data'][i]['id']} onclick=deleteSchool(this)>删除</button></td>`)
    }
    $('.school i').on('click',()=>{
        layer.prompt({title: '请输入文本'}, async function(value, index, elem){
            if(value === '') return elem.focus();

            response=await taskObject.fetchtemplate(path='/api/admin/school',method='POST',data={'name':value})
             if(response['code']!=200){
                setTimeout(()=>{
                    taskObject.layerErrorView("网络异常");
                },1000)
                layer.close(index);
                return ;
             }
             taskObject.layerSuccessView('创建成功')
             setTimeout(()=>{
                window.location.reload()
             },2000)
             layer.close(index);
             return ;
             
            
          });
    })
}())
async function deleteSchool(even){
    let array=even.id.split('a')
    valueId=parseInt(array[0])
    if (array.length==2){
        valueId=parseInt(array[1])
    }
   
    
    if(array.length==2){
        //collegetype
        response=await taskObject.fetchtemplate(path='/api/admin/school',method='DELETE',data={'collegeid':valueId,'collegetype':1})
   
    }else{
        response=await taskObject.fetchtemplate(path='/api/admin/school',method='DELETE',data={'collegeid':valueId})

    }
  if (response['code']!=200){
        setTimeout(()=>{
            taskObject.layerErrorView(response['message'])
        },1500)
        return ;
    }
    setTimeout(()=>{
      window.location.reload()
    },1500)
    layer.msg('删除成功', {icon: 1,time:1500})
}